package com.lanou.bookstore.order.web.servlet;

import com.lanou.bookstore.book.domain.Book;
import com.lanou.bookstore.cart.domain.Cart;
import com.lanou.bookstore.cart.domain.CartItem;
import com.lanou.bookstore.order.domain.Order;
import com.lanou.bookstore.order.domain.OrderItem;
import com.lanou.bookstore.order.service.OrderService;
import com.lanou.bookstore.user.domain.User;
import com.lanou.bookstore.util.BaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

@WebServlet(name = "OrderServlet",urlPatterns = "/order.do")
public class OrderServlet extends BaseServlet {
    private OrderService orderService = new OrderService();

    private void orders(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User user = (User) request.getSession().getAttribute("user");
        if (user == null) {
            response.sendRedirect(request.getContextPath() + "/jsps/user/login.jsp");
            return;
        }
        List<Order> orders = orderService.findByUid(user.getUid());
        request.setAttribute("orders", orders);
        request.getRequestDispatcher("/jsps/order/list.jsp")
                .forward(request, response);
    }

    private void load(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String oid = request.getParameter("oid");
        //点击付款,按oid查询该订单
        Order order = orderService.load(oid);
        request.setAttribute("order", order);
        request.getRequestDispatcher("/jsps/order/desc.jsp")
                .forward(request, response);
    }

}
